package org.xyf.common;

public class AjaxResult<T> {

    private int code;
    private String message;
    private T data;

    public AjaxResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 快速生成成功响应（无数据）
    public static <T> AjaxResult<T> success() {
        return new AjaxResult<>(200, "Success", null);
    }

    public static <T> AjaxResult<T> success(T data) {
        return new AjaxResult<>(200, "Success", data);
    }

    public static <T> AjaxResult<T> fail(int code, String message) {
        return new AjaxResult<>(code, message, null);
    }

    public static <T> AjaxResult<T> fail(String message) {
        return new AjaxResult<>(500, message, null);
    }

    public static <T> AjaxResult<T> unauthorized(String message) {
        return fail(401, message);
    }

    public static <T> AjaxResult<T> forbidden(String message) {
        return fail(403, message);
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }
}
